package smart.rpc.server;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created By gao_e on 2020/3/10 0:24
 */
public class ServerServiceContainer {

    // 具体服务提供者service映射  K:serviceName, V:serviceBean
    private static Map<String, Object> serviceMap = new ConcurrentHashMap<>(512);

    public static void addAllService(Map<String, Object> beans) {
        serviceMap.putAll(beans);
    }

    public static void addServer(String serviceClassFullName, Object bean) {
        serviceMap.put(serviceClassFullName, bean);
    }

    public static Set<String> getServiceClassFullNames() {
        return serviceMap.keySet();
    }

    public static Object getBeanByServiceFullBame(String serviceFullName) {
        Object bean = serviceMap.get(serviceFullName);
        if (bean == null)
            throw new RuntimeException("Service bean not exixt , serviceFullName is " + serviceFullName);
        return bean;
    }


}
